package com.serviceImpl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.dao.manager.RegistrationMapper;
import com.pojo.Registration;
import com.service.RegistrationService;
import com.utils.UUIDUtils;

@Service
public class RegistrationServiceImp implements RegistrationService {

	@Resource
	private RegistrationMapper registrationMapper;

	@Override
	public int addRegistrationInfo(Map<String, String> paramsMap) {
		try {
			String uuid = UUIDUtils.getUUID();
			Registration entity = new Registration();
			entity.setUuid(uuid);
			entity.setDeviceid(Integer.valueOf(paramsMap.get("deviceid")));
			entity.setDevicecode(paramsMap.get("devicecode"));
			entity.setCompany(paramsMap.get("company"));
			entity.setKaneyasuname(paramsMap.get("kaneyasuname"));
			entity.setCreatetime(new Date());
			registrationMapper.addRegistrationInfo(entity);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public int deleteRegistrationInfo(Map<String, String> paramsMap) {
		try {
			return registrationMapper.deleteRegistrationInfo(paramsMap);
		} catch (Exception e) {
			e.printStackTrace();
			return -2;
		}
	}

	@Override
	public int updateRegistrationInfo(Map<String, String> paramsMap) {
		try {
			String uuid = paramsMap.get("uuid");
			Registration entity = new Registration();
			entity.setUuid(uuid);
			entity.setDevicecode(paramsMap.get("devicecode"));
			entity.setCompany(paramsMap.get("company"));
			entity.setKaneyasuname(paramsMap.get("kaneyasuName"));
			entity.setCreatetime(new Date());
			registrationMapper.updateRegistrationInfo(entity);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public List<Map<String, String>> getRegistrationInfo(Map<String, String> paramsMap) {
		String page = paramsMap.get("page");
		if (page == null || "".equals(page)) {
			page = "1";
		}
		String num = paramsMap.get("num");
		if (num == null || "".equals(num)) {
			num = "10";
			paramsMap.put("num", num);
		}
		int start = (Integer.parseInt(page) - 1) * Integer.parseInt(num);
		paramsMap.put("start", start + "");
		return registrationMapper.getRegistrationInfo(paramsMap);
	}

	@Override
	public List<Map<String, String>> getRegistrationById(Map<String, String> paramsMap) {
		return registrationMapper.getRegistrationById(paramsMap.get("id"));
	}
	@Override
	public Map<String, String> getRegistration(Map<String, String> paramsMap) {
		return registrationMapper.getRegistration(paramsMap.get("id"));
	}

	@Override
	public List<Map<String, String>> getRegistrationByDeviceId(Map<String, String> paramsMap) {
		return registrationMapper.getRegistrationByDeviceId(paramsMap.get("id"));
	}
}
